package com.quasar.hpatient.module.comm_card;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.quasar.hpatient.R;

import lib.quasar.base.frame.BaseActivity;
import lib.quasar.util.GlideUtil;

/**
 * description: 我的名片
 * created by kalu on 2018/4/8 13:57
 */
public class CardActivity extends BaseActivity<CardPresenter> implements CardView, View.OnClickListener {

    @Override
    public int initView() {
        return R.layout.activity_comm_card;
    }

    @Override
    public void initDataLocal() {

        findViewById(R.id.comm_card_back).setOnClickListener(this);

        CardPresenter presenter = getPresenter();
        if (null == presenter) return;
        presenter.requestQrcode(getApplicationContext(), this);
        presenter.requestHead(getApplicationContext(), this);
        presenter.requestName(getApplicationContext(), this);
    }

    @Override
    public void initDataNet() {

    }

    @Override
    public void setText(int id, String str) {
        TextView text = findViewById(id);
        if (null == text || TextUtils.isEmpty(str)) return;
        text.setText(str);
    }

    @Override
    public void setQrcode(int id, Bitmap bitmap) {

        ImageView qrcode = findViewById(id);
        if (null == qrcode || null == bitmap) return;
        qrcode.setImageBitmap(bitmap);
    }

    @Override
    public void setHead(int id, String url) {
        ImageView head = findViewById(id);
        if (null == head || TextUtils.isEmpty(url)) return;
        GlideUtil.loadImageCircle(this, head, url);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.comm_card_back:
                onBackPressed();
                break;
        }
    }
}